package JAVA300.第十二章网络编程;

import com.sun.jndi.toolkit.url.UrlUtil;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * URL
 */
public class Web02_UrlTest {
    public static void main(String[] args) throws MalformedURLException {

        URL url= new URL("http://www.baidu.com:80/index.html?uname=shsxt&age=18#a");

        //获取URL四个组成部分
        System.out.println("协议"+url.getProtocol());
        System.out.println("域名/IP"+url.getHost());
        System.out.println("请求端口"+url.getPort());
        System.out.println("请求资源"+url.getPath());
        System.out.println("请求资源1"+url.getFile());

        //获取参数
        System.out.println("参数"+url.getQuery());//参数uname=shsxt&age=18

        //获取锚地
        System.out.println("锚点"+url.getRef());//锚点a


    }
}
